//
//  XCTabBarButton.m
//  CreditAddressBook
//
//  Created by Lee on 15/4/22.
//  Copyright (c) 2015年 Lee. All rights reserved.
//

#define XCTabBarButtonImageRatio 0.5

#import "XCTabBarButton.h"

@implementation XCTabBarButton

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView.contentMode = UIViewContentModeScaleAspectFit;//使imageView跟随Image大小改变
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel.font = CYTabBarTitleFont;
    }
    return self;
}

- (void)awakeFromNib {
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;//使imageView跟随Image大小改变
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = CYTabBarTitleFont;
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect {
    CGFloat imageW = contentRect.size.width/3;
    CGFloat imageH = (contentRect.size.height - 0) * XCTabBarButtonImageRatio;
    return CGRectMake(imageW, 5, imageW, imageH);
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect {
    CGFloat titleW = contentRect.size.width;
    CGFloat titleY = contentRect.size.height * XCTabBarButtonImageRatio + 3;
    CGFloat titleH = contentRect.size.height - titleY;
    return CGRectMake(0, titleY, titleW, titleH);
}

@end
